package com.cmbc.thread;

public class Window extends Thread{
	static int ticket=20;
	static String key="12306";
	@Override
	public void run() {
		while(ticket>0) {
			synchronized (key) {
				if(ticket>0) {
					System.out.println(getName()+"窗口卖出第"+ticket+"张票");
					ticket--;
				}
			}
			try {
				sleep(1000L);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}
